﻿using BLL.Core;
using Castle.Core;
using Castle.DynamicProxy;
using Castle.MicroKernel.Registration;
using Castle.MicroKernel.SubSystems.Configuration;
using Castle.Windsor;
using Castle.Windsor.Installer;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace CW.Shell
{
    public class ClsInterceptor : IInterceptor
    {
        public void Intercept(IInvocation invocation)
        {
            var f = new System.Diagnostics.StackFrame();
            System.Diagnostics.Trace.TraceInformation(f.GetFileLineNumber().ToString());
            try
            {
                invocation.Proceed();
                System.Diagnostics.Trace.TraceInformation(f.GetFileLineNumber().ToString());
            }
            catch (Exception)
            {

                System.Diagnostics.Trace.TraceInformation(f.GetFileLineNumber().ToString());
            }
            finally
            {

                System.Diagnostics.Trace.TraceInformation(f.GetFileLineNumber().ToString());
            }
        }
    }

    [Interceptor(typeof(ClsInterceptor))]
    public class MonitorCls
    {
        public static void Init(string[] args)
        {

        }

        public void Run(string[] args)
        {

        }
    }

    public class Installer : IWindsorInstaller
    {
        public void Install(IWindsorContainer container, IConfigurationStore store)
        {
            //container.Install(
            //      FromAssembly.This(),
            //      FromAssembly.Named("Acme.Crm.Bootstrap"),
            //      FromAssembly.Containing<Installer>(),
            //      FromAssembly.InDirectory(new AssemblyFilter("Extensions")),
            //      FromAssembly.Instance(this.GetPluginAssembly())
            //      );

            container.Register(Component
                .For<ICoreService>()
                //.ImplementedBy<CoreService>()
                .LifestyleSingleton()
                .Instance(CoreService.Instance));
        }

        private Assembly GetPluginAssembly()
        {
            return null;
        }
    }
}
